﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Gargoyle.ZZT
{
    public delegate bool DirectionDelegate(Game g, Thing thing, ref Int16 offset, ref Vector vector);

    static class Directions
    {
        public static bool Clockwise(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            if (g.ReadDirection(thing, ref offset, ref vector))
            {
                vector = vector.Clockwise();
                return true;
            }
            return false;
        }

        public static bool CounterClockwise(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            if (g.ReadDirection(thing, ref offset, ref vector))
            {
                vector = vector.CounterClockwise();
                return true;
            }
            return false;
        }

        public static bool East(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = Vector.East();
            return true;
        }

        public static bool Flow(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = thing.Vector;
            return true;
        }

        public static bool Idle(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = Vector.Idle();
            return true;
        }

        public static bool North(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = Vector.North();
            return true;
        }

        public static bool Opp(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            if (g.ReadDirection(thing, ref offset, ref vector))
            {
                vector = vector.Opposite();
                return true;
            }
            return false;
        }

        public static bool Rnd(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = g.Rnd();
            return true;
        }

        public static bool RndNE(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = g.RndNE();
            return true;
        }

        public static bool RndNS(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = g.RndNS();
            return true;
        }

        public static bool RndP(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            if (g.ReadDirection(thing, ref offset, ref vector))
            {
                vector = g.RndP(vector);
                return true;
            }
            return false;
        }

        public static bool Seek(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = g.Seek(thing.Location);
            return true;
        }

        public static bool South(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = Vector.South();
            return true;
        }

        public static bool West(Game g, Thing thing, ref Int16 offset, ref Vector vector)
        {
            vector = Vector.West();
            return true;
        }
    }
}
